#include<bits/stdc++.h>

using namespace std;
int a[1024];
char s[1024];

int cal(int begin, int end, int prev_min) {
    int t;
    int min = 4;
    int min_i;
    for (int i = begin; i <= end; i++) {
        switch (s[i]) {
            case '^':
                if (min > 3)
                    min = 3, min_i = i;
                break;
            case '*':
            case '/':
                if (min > 2)
                    min = 2, min_i = i;
                break;
            case '+':
            case '-':
                if (min > 1)
                    min = 1, min_i = i;
                break;
            case '(':
                i++;
                for (t = 1; t != 0; i++) {
                    if (s[i] == '(')
                        t++;
                    if (s[i] == ')')
                        t--;
                }
                i--;
                break;
        };
    }

    if (min == 4) {
        if (s[begin] == '(' && s[end] == ')') {
            t = cal(begin + 1, end - 1, 0);
            if (t >= prev_min) {
                a[begin] = a[end] = 1;
                return t;
            }
        }
        return 4;
    }


    cal(begin, min_i - 1, min);
    if (s[min_i] == '+' || s[min_i] == '*')
        cal(min_i + 1, end, min);
    else
        cal(min_i + 1, end, min + 1);
    return min;
}


int main() {
    while (cin >> s && s[0] != '#') {
        int sc = strlen(s);
        cal(0, sc - 1, 0);
        for (int i = 0; i < sc; i++) {
            if (!a[i])
                cout << s[i];
        }
        memset(s, 0, sizeof(s));
        memset(a, 0, sizeof(s));
        cout << "\n";
    }
    return 0;
} 